package ru.vsu.cs.kis.elections.parser;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;

import ru.vsu.cs.kis.elections.socketexchenge.commands.Command;

public  class ObjStreamParser {

	public static Command parseToCommand(InputStream streamForParse) {
		Command result=null;
		try {
			ObjectInputStream ois = new ObjectInputStream(streamForParse);
			result=(Command)ois.readObject();
			return result;
		} catch (IOException Ex) {
			Ex.printStackTrace(System.err);
			return result;
		}		
		catch (ClassNotFoundException Ex) {
			Ex.printStackTrace(System.err);
			return result;
		}
	}

	public static  Boolean parseToStream(Command comForParse, OutputStream streamForParse) {
		try {
			ObjectOutputStream oos = new ObjectOutputStream(streamForParse);
			oos.writeObject(comForParse);
			oos.flush();
			return true;
		} catch (IOException Ex) {
			Ex.printStackTrace(System.err);
			return false;
		}		
	}
}
